package com.hdf.etdemo.view.listview;

import java.util.ArrayList;
import java.util.List;

import com.hdf.easytools.base.EasyToolsActivity;
import com.hdf.easytools.view.listview.view.XListView;
import com.hdf.easytools.view.listview.view.XListView.IXListViewListener;
import com.hdf.easytools.view.viewpage.CycleViewPager;
import com.hdf.easytools.view.viewpage.CycleViewPager.ImageCycleViewListener;
import com.hdf.easytools.view.viewpage.ViewFactory;
import com.hdf.easytools.view.viewpage.bean.CycleVpEntity;
import com.hdf.etdemo.R;
import com.hdf.etdemo.uitl.DemoUtil;
import com.hdf.etdemo.view.listview.adapter.ListViewAdapter;
import com.jeremyfeinstein.slidingmenu.lib.SlidingMenu;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;

public class ViewPageListViewActivity extends EasyToolsActivity implements IXListViewListener {
	private XListView mListView;
	// 只是用来模拟异步获取数据
	private Handler handler;
	private CycleViewPager cycleViewPager;
	private View vhdf;

	// 侧滑菜单
	private SlidingMenu menu;
	// 侧滑菜单
	private SlidingMenu menu2;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_viewpage_listview);

		if (DemoUtil.getType(ViewPageListViewActivity.this).equals("menu")){
			titlestyle2();
			SlidingMenu();// 左侧菜单
			SlidingMenu2();// 右侧菜单
		}
		else
			titlestyle();
		handler = new Handler();
		mListView = (XListView) findViewById(R.id.xListView);
		// 设置xlistview可以加载、刷新
		mListView.setPullLoadEnable(true);
		mListView.setPullRefreshEnable(true);
		mListView.setXListViewListener(this);
		mListView.setRefreshTime(DemoUtil.getDetailTime(System.currentTimeMillis() + ""));
		mListView.setAdapter(new ListViewAdapter(this, DemoUtil.demoData()));
		// 三句话 调用轮播广告
		vhdf = getLayoutInflater().inflate(R.layout.viewpage, null);
		cycleViewPager = (CycleViewPager) getFragmentManager().findFragmentById(R.id.fragment_cycle_viewpager_content);
		ViewFactory.initialize(ViewPageListViewActivity.this, vhdf, cycleViewPager, DemoUtil.cycData());
		mListView.addHeaderView(vhdf);

	}

	public void titlestyle2() {
		/** 设置标题显示 */
		this.TitleVisib(0, 1, 1, 1, 0);
		/** 绑定标题点击事件 */
		this.TitleClick(0, 1, 0, 1, 0);
		/** 设置标题样式ʽ */
		this.TitleStyle(null, R.drawable.et_back, "ViewPage", "侧滑菜单", 0);
	}

	public void titlestyle() {
		/** 设置标题显示 */
		this.TitleVisib(0, 1, 1, 0, 0);
		/** 绑定标题点击事件 */
		this.TitleClick(0, 1, 0, 0, 0);
		/** 设置标题样式ʽ */
		this.TitleStyle(null, R.drawable.et_back, "ViewPage", null, 0);
	}

	/**
	 * SlidingMenu侧滑菜单
	 */
	public void SlidingMenu() {
		menu = new SlidingMenu(this);
		menu.setMode(SlidingMenu.LEFT);
		// 设置触摸屏幕的模式
		menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_MARGIN);
		// 设置滑动菜单视图的宽度
		menu.setBehindOffsetRes(R.dimen.activity_menu_winth);
		// 设置背景图
		// menu.setBackgroundResource(R.drawable.left_new_background);
		// 设置渐入渐出效果的值
		menu.setFadeDegree(0.35f);
		menu.attachToActivity(this, SlidingMenu.SLIDING_CONTENT);
		// 为侧滑菜单设置布局
		menu.setMenu(R.layout.slidingmenu);
		Button btn = (Button) menu.findViewById(R.id.slibtn1);
		btn.setText("打开右侧菜单");
		btn.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				menu2.toggle();
				menu.toggle();
			}
		});

	}

	/**
	 * SlidingMenu侧滑菜单
	 */
	public void SlidingMenu2() {
		menu2 = new SlidingMenu(this);
		menu2.setMode(SlidingMenu.RIGHT);
		// 设置触摸屏幕的模式
		menu2.setTouchModeAbove(SlidingMenu.TOUCHMODE_MARGIN);
		// 设置滑动菜单视图的宽度
		menu2.setBehindOffsetRes(R.dimen.activity_menu_winth);
		// 设置背景图
		// menu.setBackgroundResource(R.drawable.left_new_background);
		// 设置渐入渐出效果的值
		menu2.setFadeDegree(0.35f);
		menu2.attachToActivity(this, SlidingMenu.SLIDING_CONTENT);
		// 为侧滑菜单设置布局
		menu2.setMenu(R.layout.slidingmenu);
		Button btn = (Button) menu2.findViewById(R.id.slibtn1);
		btn.setText("打开左侧菜单");
		btn.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				menu.toggle();
				menu2.toggle();
			}
		});

	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.left_img:
			finish();
			break;
		case R.id.right_text:
			menu.toggle();
			break;

		default:
			break;
		}

	}

	@Override
	public void onRefresh() {
		// TODO Auto-generated method stub
		handler.postDelayed(new Runnable() {

			@Override
			public void run() {
				mListView.stopRefresh();
				Toast.makeText(ViewPageListViewActivity.this, "刷新", 30).show();
			}
		}, 1000);
	}

	@Override
	public void onLoadMore() {
		// TODO Auto-generated method stub
		handler.postDelayed(new Runnable() {

			@Override
			public void run() {
				mListView.stopRefresh();
				// mListView.getFooterView().setHaveData();
				mListView.setPullLoadEnable(false);
				Toast.makeText(ViewPageListViewActivity.this, "加载更多", 30).show();

			}
		}, 1000);

	}
}